#! /usr/bin/env python
# -*- coding:utf-8 -*-
# author:无涯


import grpc
from  concurrent import  futures
import  time ,os
import helloworld_pb2
import helloworld_pb2_grpc


class HelloWorldServer(helloworld_pb2_grpc.GreeterServicer):
   def SayHello(self,request,context):
      '''客户端与服务端来进行交互'''
      return helloworld_pb2.HelloReply(
         msg='{0}'.format(request.data),
         code='True')

def serve():
   server=grpc.server(futures.ThreadPoolExecutor(max_workers=os.cpu_count()))
   helloworld_pb2_grpc.add_GreeterServicer_to_server(HelloWorldServer(), server)
   server.add_insecure_port('[::]:60061')
   server.start()
   try:
      while True:
         time.sleep(60*60*24)
   except KeyboardInterrupt as e:
      server.stop(0)

if __name__ == '__main__':
   serve()